﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace WebLog.Db.Update
{
    internal class update_v2_1 : baseUpdateDatabase
    {
        public update_v2_1()
        {
            this.V = 2.1;
            this.Memo = "添加列 weblog Complete；升级Edition表";
        }
        internal override async Task UpdateAction()
        {
            try
            {
                await sqliteHelper.ExecuteNonQueryAsync(@"ALTER TABLE  weblog ADD COLUMN  Complete double;");
            }
            catch (Exception)
            {
                await sysLogHelper.AppendSysLog("增加字段Complete失败(weblog)", this.V + "");
            }
            await sqliteHelper.ExecuteNonQueryAsync(@"
                    DROP TABLE if exists EditionTmp;
                    create table if not exists EditionTmp(
                        id integer PRIMARY KEY autoincrement,                -- 设置主键
                        V double,
                        Memo VARCHAR(500),--版本简介
                        Date DATETIME--更新版本的时间
                    );
                    INSERT INTO EditionTmp(V) select V from Edition;
                    drop table Edition;
                    alter table EditionTmp rename to Edition;
                ");
            /*
            添加列 weblog Complete；升级Edition表
             */
        }
    }
}
